<?php 
//Start session
	@session_start();
	
	//Include database connection details
	require_once('inc/config.inc');
	
	
	
	//Connect to mysql server
	$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
	if(!$link) {
		die('Failed to connect to server: ' . mysql_error());
	}
	
	//Select database
	$db = mysql_select_db(DB_DATABASE);
	if(!$db) {
		die("Unable to select database");
	}
	$select = mysql_query("SELECT f.file_name
							   FROM course_materials m,material_file f
							   WHERE m.course_id='".$_GET['course_id']."' AND m.material_id=f.material_id");
	$query = mysql_query("delete from courses where id='".$_GET['course_id']."'");
	if($query){
			while($row = mysql_fetch_array($select)){
				unlink("../uploads/".$row[0]);
			}
		echo "<button type='button' class='close' data-dismiss='alert'>&times;</button><strong>SUCCESS: </strong>Course Deleted Successfully";
	}
	else {
		echo "<button type='button' class='close' data-dismiss='alert'>&times;</button><strong>ERROR: </strong>NOT deleted: ".mysql_error();
	}	
?>